BUILD="./test/build"
PRE="./test/pre"
TEST="./test/src"
SRC="./src"
INCLUDE="./src/include"
.PHONY:common
common:
	gcc -g3 $(TEST)/common.c -I $(SRC)/include -o $(BUILD)/$@

pre-common:
	gcc -E $(TEST)/common.c -I $(SRC)/include -o $(PRE)/$@

test-common: common
	$(BUILD)/common

debug-common: common
	gdb $(BUILD)/common

.PHONY:base64
base64:
	gcc -g3 $(TEST)/base64.c $(SRC)/base64/base64.c -I $(SRC)/include -o $(BUILD)/$@

test-base64: base64
	$(BUILD)/base64

debug-base64: base64
	gdb $(BUILD)/base64

.PHONY:md5
md5:
	gcc -g3 $(TEST)/md5.c $(SRC)/md5/md5.c $(SRC)/md5/md5tool.c $(SRC)/tool/tool.c $(SRC)/tool/log.c -I $(SRC)/include -lm -o $(BUILD)/$@

test-md5:
	$(BUILD)/md5

debug-md5:
	gdb $(BUILD)/md5


.PHONY:bits
bits:
	gcc -g3 $(TEST)/bits.c $(SRC)/tool/bits.c -I $(SRC)/include -lm -o $(BUILD)/$@

test-bits:des
	$(BUILD)/bits

debug-bits:
	gdb $(BUILD)/bits

.PHONY:des
des:
	gcc -g3 $(TEST)/des.c $(SRC)/tool/bits.c $(SRC)/des/des.c $(SRC)/des/destool.c -I $(SRC)/include -lm -o $(BUILD)/$@

test-des:des
	$(BUILD)/des

debug-des:
	gdb $(BUILD)/des

.PHONY:bignum
bignum:
	gcc -g3 $(TEST)/bignum.c $(SRC)/tool/bignum.c $(SRC)/tool/tool.c -I $(SRC)/include -lm -o $(BUILD)/$@

pre-bignum:
	gcc -E $(SRC)/tool/bignum.c -I $(SRC)/include -lm -o $(PRE)/$@

test-bignum:bignum
	$(BUILD)/bignum

debug-bignum:
	gdb $(BUILD)/bignum

hash:
	gcc -g3 $(TEST)/hash.c -I $(SRC)/include -lm -o $(BUILD)/$@

test-hash:hash
	$(BUILD)/hash

debug-hash:
	gdb $(BUILD)/hash

json:
	gcc -g3 $(TEST)/json.c $(SRC)/tool/json.c $(SRC)/tool/tool.c  $(SRC)/tool/log.c $(SRC)/parse/json/ParseJsonImp.c $(SRC)/parse/json/json.l.c $(SRC)/parse/json/json.y.c -I $(SRC)/include -lm -o $(BUILD)/$@

test-json:json
	$(BUILD)/json

debug-json:
	gdb $(BUILD)/json


# .PHONY:parse
# parse:
# 	flex -o $(SRC)/parse/json/json.flex.c $(SRC)/parse/json/json.l 
# 	bison --yacc -dv $(SRC)/parse/json/json.flex.c
# 	mv y.tab.c -o $(SRC)/parse/json/json.yacc.c
# 	gcc -g3 $(SRC)/parse/json/json.flex.c $(SRC)/parse/json/json.yacc.c -I $(SRC)/include -lm -o $(BUILD)/$@

# test-parse:parse
# 	$(BUILD)/parse

# debug-parse:
# 	gdb $(BUILD)/parse

.PHONY:sqlite3
sqlite3:
	gcc -g3 $(TEST)/sqlite3.c  -I $(SRC)/include -l sqlite3 -o $(BUILD)/$@

test-sqlite3:sqlite3
	$(BUILD)/sqlite3

debug-sqlite3:
	gcc test.c -l 

.PHONY:tcpserver
tcpserver:
	gcc -g3 $(TEST)/tcpserver.c $(SRC)/tcp/server.c -I $(SRC)/include -lm -o $(BUILD)/$@

test-tcpserver:tcpserver
	$(BUILD)/tcpserver

debug-tcpserver:
	gdb $(BUILD)/tcpserver

.PHONY:tcpclient
tcpclient:
	gcc -g3 $(TEST)/tcpclient.c $(SRC)/tcp/client.c -I $(SRC)/include -lm -o $(BUILD)/$@

test-tcpclient:tcpclient
	$(BUILD)/tcpclient

debug-tcpclient:
	gdb $(BUILD)/tcpclient

.PHONY:jsonparse
jsonparse:
	bison -o $(SRC)/parse/json/json.y.c $(SRC)/parse/json/json.y
	bison -do $(INCLUDE)/crypto/parse/json/json.y.h $(SRC)/parse/json/json.y
	flex -o $(SRC)/parse/json/json.l.c --header-file=$(INCLUDE)/crypto/parse/json/json.l.h $(SRC)/parse/json/json.l
	
test-jsonparse:jsonparse
	gcc -g3 $(TEST)/jsonparse.c $(SRC)/tool/json.c $(SRC)/tool/tool.c $(SRC)/tool/log.c $(SRC)/parse/json/ParseJsonImp.c $(SRC)/parse/json/json.l.c $(SRC)/parse/json/json.y.c -I $(SRC)/include -lm -o $(BUILD)/jsonparse
	$(BUILD)/jsonparse

debug-jsonparse:
	gdb $(BUILD)/jsonparse


.PHONY:rsa
rsa:
	gcc -g3 $(TEST)/rsa.c $(SRC)/tool/tool.c $(SRC)/rsa/rsa.c $(SRC)/tool/log.c -I $(SRC)/include -lm -o $(BUILD)/$@
test-rsa:rsa
	$(BUILD)/rsa

debug-rsa:
	gdb $(BUILD)/rsa


.PHONY:pthread
pthread:
	gcc -g3 $(TEST)/pthread.c  -I $(SRC)/include -lm -lpthread -o $(BUILD)/$@

test-pthread:pthread
	$(BUILD)/pthread

debug-pthread:
	gdb $(BUILD)/pthread

.PHONY:tlsclient
tlsclient: jsonparse
	gcc -g3 $(TEST)/tlsclient.c `find $(SRC) -name *.c | grep -v server.c` -I $(SRC)/include -lm -lpthread -o $(BUILD)/$@

tlsclient-test:tlsclient
	$(BUILD)/tlsclient

tlsclient-debug:
	gdb $(BUILD)/tlsclient

.PHONY:tlsserver
tlsserver: jsonparse
	gcc -g3 $(TEST)/tlsserver.c `find $(SRC) -name *.c | grep -v client.c` -I $(SRC)/include -lm -lpthread -o $(BUILD)/$@

tlsserver-test:tlsserver
	$(BUILD)/tlsserver

tlsserver-debug:
	gdb $(BUILD)/tlsserver

.PHONY:&&&&
&&&&:
	gcc -g3 $(TEST)/tlsserver.c `find .$(SRC) -name *.c | grep -v tlsclient.c` -I .$(SRC)/include -lm -lpthread -o $(BUILD)/$@

test-&&&&:&&&&
	$(BUILD)/&&&&

debug-&&&&:
	gdb $(BUILD)/&&&&

